<script setup lang="ts">
// as起别名 给Button起一个别名VanButton 原来的别名不可以用了
import { Button as VanButton } from 'vant'
import { useLoginStore } from '@/stores'
import { storeToRefs } from 'pinia'
import { request } from '@/utils/request'
import type { LoginUser, UserInfo } from '@/types/user'
const store = useLoginStore()
const { loginUser } = storeToRefs(store)
const { updataLogin, delLoginUser } = store
const getUserInfo = () => {
  request<UserInfo>('/patient/myUser')
    .then((res) => {
      console.log(res)
      res.data.orderInfo.finishedNumber
    })
    .catch((err) => {
      console.log(err)
    })
}
const login = () => {
  request<LoginUser>('/login/password', 'post', {
    password: '11111111',
    mobile: '13811111111'
  })
    .then((res) => {
      console.log(res)
      res.data.avatar
    })
    .catch((err) => {
      console.log(err)
    })
}
</script>

<template>
  <!-- 验证vant颜色被覆盖 -->
  <div>用户信息：{{ loginUser }}</div>
  <van-button
    type="primary"
    @click="
      updataLogin({
        token: '1',
        refreshToken: '1',
        avatar: '1',
        mobile: '1',
        account: '1',
        id: '1'
      })
    "
    >测试登录</van-button
  >
  <van-button type="primary" @click="getUserInfo">测试请求</van-button>
  <van-button type="primary" @click="delLoginUser">测试退出登录</van-button>
  <van-button type="primary" @click="login">登录携带token</van-button>
</template>
<style scoped lang="scss">
// 使用 css 变量
a {
  color: var(--cp-primary);
}
</style>
